home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_200
/
203_01
/
yam5.c
< prev
next >
Wrap
Text File
|
1980-01-01
|
17KB
|
736 lines
/*
$title ('yam5.c: user specific routines')
$date (21 OCT 85)
*/
/*
basic low-level modem functions
*/
#include <dos.h>
#include "yam.h"
char portmode; /* baud, parity, stop bit configuration byte */
unsigned io_config; /* hardware config byte */
/* offsets to status ports */
#define ierport Dport+1
#define iicport Dport+2
#define lcrport Dport+3
#define mcrport Dport+4
#define mcsport Dport+6
#define serialio 0x14
#define get_io_config 0x11
/* serial equates for int 14h in MS-DOS, IBM-PC, Zenith Z-160 */
#define baudmask 0xe0 /* baud rate mask */
#define B110 0
#define B150 0x20
#define B300 0x40
#define B600 0x60
#define B1200 0x80
#define B2400 0xA0
#define B4800 0xC0
#define B9600 0xE0
#define wlenmask 0x3 /* word length mask */
#define len7 2
#define len8 3
#define parmask 0x18 /* mask for parity bits */
#define nopar 0
#define even 0x18
#define odd 0x8
#define stopmask 0x4 /* mask for stop bits */
#define stop1 0x0
#define stop2 0x4
/* modem command equates for 8251 */
#define dtr 0x01
#define rts 0x02
#define l6mode (len7 | even | stop2)
#define normode (len8 | stop1 | nopar)
/****************************************************************************
FUNCTION:
send initialzation sequence to CRT. Some people like the screen to
be cleared, etc.
CALLING PARAMETERS:
none.
===========================================================================*/
terminit()
{
} /* terminit */
/****************************************************************************
FUNCTION:
change modem port to alternate modem port. Only ports 0 and 1 are
supported as interrupts must be available for the driver.
CALLING PARAMETERS:
port:
number of port to change to. For IBM PC, this is 0 or 1
===========================================================================*/
chngport(port)
int port;
{
/* first check to see if port exists. bits 9-11 of confuration
says how many ports in system */
if ( (port > ( (io_config>>9)&0x7)-1) || (port > 1) )
{
printf("port not availablet\n");
return ERROR;
}
else
{
/* disable current port */
dsblcm();
resport(commport);
/* set new port */
switch(port)
{
case 1:
Dport = 0x2f8;
commport = 1;
break;
default:
Dport = 0x3f8;
commport = 0;
}
}
/* enable new port */
setport(commport);
enblcm(0);
return OK;
} /* chngport */
/****************************************************************************
FUNCTION:
peform special user init routines. Called from INIT() at load time
with resetflag false. Called from RESET with resetflag true. If reset
flag is true, the port will be reset to the last value as defined by set
baud, or initialization. This allows the port to be reset and the current
state of the port displayed. Some systems allow configuration of the
serial port to be read. IBM does not, so to retain IBM compatiblity
that data is assumed unavailable.
CALLING PARAMETERS:
resetflag:
if true, serial port and modem will be initialzed to default condition.
===========================================================================*/
userinit(resetflag)
int resetflag;
{
union REGS inregs;
union REGS outregs;
/* get i/o configuration byte */
int86(get_io_config,&inregs,&outregs);
io_config = outregs.x.ax;
/* reset port mode */
if (resetflag)
{
/* baudrate is already set to a default value */
setbaud(Baudrate);
/* modem will not accept command unless TR is true(terminal
ready) */
offhook();
/* set modem configuration:
wait 100 seconds for carrier
answer on first ring
enable connect 1200 message,
echo result codes
*/
sendstring("ATS7=100 S0=1 X1 Q0\r");
/* slight delay needed after commands */
sleep(5);
/* set back on hook so will not answer phone */
onhook();
}
} /* userinit */
/****************************************************************************
FUNCTION:
perform user required clean up before exit
CALLING PARAMETERS:
none.
===========================================================================*/
userexit()
{
/* reset comm port interrupt */
resport(commport);
/* disable interrupts */
dsblcm();
/* reset interrupt vectors */
res_comm();
}
/****************************************************************************
FUNCTION:
set serial port mode. Baud rate, start, stop and parity are set
via interrupt 14h.
CALLING PARAMETERS:
mode:
mode byte as defined in int 14h.
===========================================================================*/
setmode(mode)
char mode;
{
union REGS inregs;
union REGS outregs;
/* dx contains port number */
inregs.x.dx = commport;
/* this routine always does a set command */
inregs.h.ah = 0;
/* set mode */
inregs.h.al = mode;
/* send command thru bios */
int86(serialio,&inregs,&outregs);
if (outregs.h.ah & 0x80)
printf("MODEM PORT TIMEOUT STATUS= %x \007\n",outregs.x.ax);
} /* setmode */
/****************************************************************************
FUNCTION:
set baud rate for serial port. This routine uses the monitor setup
routine, which should be compatible with most IBM PC's.
CALLING PARAMETERS:
baud:
unsigned integer representing baud rate desired.
===========================================================================*/
setbaud(baud)
int baud;
{
unsigned ratediv;
Baudrate = baud;
switch(baud)
{
case 110:
ratediv = B110;
break;
case 150:
ratediv = B150;
break;
case 300:
ratediv = B300;
break;
case 600:
ratediv = B600;
break;
case 1200:
ratediv = B1200;
break;
case 2400:
ratediv = B2400;
break;
case 4800:
ratediv = B4800;
break;
case 9600:
ratediv = B9600;
break;
default: /* use existing rate */
Baudrate=readbaud();
ratediv = portmode & baudmask;
}
/* set serial port baud rate */
portmode = ((portmode & ~baudmask) | ratediv);
setmode(portmode);
display_status();
} /* setbaud */
/****************************************************************************
FUNCTION:
print modem status to console.
CALLING PARAMETERS:
none.
===========================================================================*/
display_status()
{
char mode;
mode = portmode & 0x1f;
if (mode == l6mode)
printf("Level 6");
else if (mode == normode)
printf("normal");
else
printf("special");
printf(" mode\n");
printf("Baud rate = %d\n",readbaud());
} /* display_status */
/****************************************************************************
FUNCTION:
send break to modem if break key is pressed.
CALLING PARAMETERS:
none.
===========================================================================*/
sendbrk()
{
char lcrval;
/* send break command */
lcrval = inp(lcrport);
outp(lcrport, (lcrval | 0x40) );
sleep(10);
outp(lcrport,lcrval);
} /* sendbrk */
/****************************************************************************
FUNCTION:
allow user to change port configuration manually. This routine builds
a string which is then used to call setparams to set port mode.
CALLING PARAMETERS:
none
===========================================================================*/
changecnfg()
{
char option;
/* mask of baud rate bits */
portmode = portmode & baudmask;
printf("stop bits (1/2)? ");
option=getopt();
switch (option)
{
case '1':
portmode = portmode | stop1;
break;
case '2':
default:
portmode = portmode | stop2;
}
printf("\nparity (E/O/N)? ");
option=getopt();
switch (option)
{
case 'e':
portmode = portmode | even;
break;
case 'o':
portmode = portmode | odd;
break;
case 'n':
default:
portmode = portmode | nopar;
}
printf("\ndata bits (7/8)? ");
option=getopt();
switch (option)
{
case '7':
portmode = portmode | le